package com.gym.controller.form.customer;

import java.sql.Date;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class FormUpdateCustomer extends ActionForm {
	
	private String email;
	private String firstname;
	private String lastname;
	private String gender;
	private String fc;
	private String phone;
	private Date bdate;

	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getFirstname() {
		return firstname;
	}
	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}
	public String getLastname() {
		return lastname;
	}
	public void setLastname(String lastname) {
		this.lastname = lastname;
	}
	public String getGender() {
		return gender;
	}
	public void setGender(String gender) {
		this.gender = gender;
	}
	public String getFc() {
		return fc;
	}
	public void setFc(String fc) {
		this.fc = fc;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public Date getBdate() {
		return bdate;
	}
	public void setBdate(Date bdate) {
		this.bdate = bdate;
	}
	
	@Override
	public ActionErrors validate(ActionMapping mapping,	HttpServletRequest request) {

		ActionErrors errors= new ActionErrors();

		if(email==null || email.isEmpty())
			errors.add("email" , new ActionMessage("it.errore.email.obbligatorio"));
		else if( ! email.matches("[-0-9a-zA-Z.+_]+@[-0-9a-zA-Z.+_]+.[a-zA-Z]{2,4}"))
			errors.add("email", new ActionMessage("it.errore.email.formato"));
		
		if(getFirstname()==null || getFirstname().isEmpty()){
			errors.add("firstname", new ActionMessage("it.errore.nome.obbligatorio"));}

		if(getLastname()==null || getLastname().isEmpty()){
			errors.add("lastname", new ActionMessage("it.errore.cognome.obbligatorio"));}

		if(getFc()==null || getFc().length()!=16 || ! getFc().matches("[a-zA-Z]{6}\\d\\d[a-zA-Z]\\d\\d[a-zA-Z]\\d\\d\\d[a-zA-Z]")){
			errors.add("fc", new ActionMessage("it.errore.fc.formato"));}

		if(getBdate()==null)
			errors.add("bdate", new ActionMessage("it.errore.bdate.obbligatorio"));
		
		return errors;

	}
}
